package com.peng.controller;

import com.github.pagehelper.PageInfo;
import com.peng.Repo.PageStatic;
import com.peng.pojo.Article;
import com.peng.pojo.ArticleType;
import com.peng.pojo.User;
import com.peng.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    //后台文章管理
    @GetMapping("/admin/article")
    public PageInfo<Article> selectAll(@RequestParam(name = "title", defaultValue = "") String title,
                                       @RequestParam(name = "publisherId", defaultValue = "0") Integer publisherId,
                                       @RequestParam(name = "typeId", defaultValue = "0") Integer typeId,
                                       @RequestParam(name = "page", defaultValue = PageStatic.page) Integer page,
                                       @RequestParam(name = "size", defaultValue = PageStatic.size) Integer size) {
        return articleService.selectAll(title, publisherId, typeId, page, size);
    }

    //修改文章状态
    @GetMapping("/admin/updateArticleStatus")
    public boolean updateArticleStatus(@RequestParam(name = "status", defaultValue = "1") Integer status,
                                       @RequestParam(name = "id") Integer... id) {
        return articleService.updateArticleStatus(status, id);
    }

    //获取讲师分类
    @GetMapping("/admin/getAllTeacherInfo")
    public List<User> getAllTeacherInfo() {
        return articleService.selectAllUser();
    }

    //获取课程分类
    @GetMapping("/admin/getAllArticleType")
    public List<ArticleType> getAllArticleType() {
        return articleService.selectAllArticleType();
    }

    //获取轮播列表
    @GetMapping("/getBroadcastingArticle")
    public List<Article> getBroadcastingArticle() {
        return articleService.selectBroadcastingArticle();
    }

    //获取最新文章列表
    @GetMapping("/home/getArticleTimeDesc")
    public List<Article> getArticleTimeDesc() {
        return articleService.selectArticleByTimeDesc();
    }

    //获取文章类型以及相应文章列表
    @GetMapping("/home/getArticleTypeAndArticle")
    public List<ArticleType> getArticleTypeAndArticle() {
        return articleService.selectArticleTypeAndArticle();
    }

    //获取文章类型下所有文章列表信息
    @GetMapping("/home/getArticleListByType/{typeId}")
    public List<Article> getArticleListByType(@PathVariable("typeId") int typeId) {
        return articleService.selectArticleByTypeId(typeId);
    }
}
